/**
 * 
 */
package com.fyp.ptma.model;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import com.fyp.ptma.xml.DateAdapter;

/**
 * @author YahyaArshad
 * 
 */
@Entity
@XmlRootElement(name = "defect")
@XmlAccessorType(XmlAccessType.NONE)
public class Defect implements Serializable {

	/**
	 * 
	 */

	public static final String DOWNLOADER = "Downloader";
	public static final String DEVELOPER = "Developer";

	private static final long serialVersionUID = 1L;
	@XmlElement
	private Long id;
	@XmlElement
	private String status;
	@XmlElement(name = "stringTimeStamp")
	@XmlJavaTypeAdapter(DateAdapter.class)
	private Timestamp date = new Timestamp(System.currentTimeMillis());
	@XmlElement
	private String commenterCode;
	@XmlElement
	private String comment;

	public Defect() {

	}

	public Defect(String comment, String commentorCode,
			ApplicationVersion version) {
		this.comment = comment;
		this.commenterCode = commentorCode;
		this.appVersion = version;
	}

	public Defect(Long id, String comment, Timestamp time, String commentorCode) {
		this.id = id;
		this.comment = comment;
		this.date = time;
		this.commenterCode = commentorCode;
	}

	// @XmlElement
	private ApplicationVersion appVersion;

	// To resolve cyclic issue in xml parsing using jaxb, using
	// applicationVersion and when we will recive app version from xml we will
	// set it to appVersion object explicitly to persist
	@XmlElement(name = "appVersion")
	private ApplicationVersion applicationVersion;

	@Transient
	public ApplicationVersion getApplicationVersion() {
		return applicationVersion;
	}

	public void setApplicationVersion(ApplicationVersion applicationVersion) {
		this.applicationVersion = applicationVersion;
	}

	public String getCommenterCode() {
		return commenterCode;
	}

	public void setCommenterCode(String commenterCode) {
		this.commenterCode = commenterCode;
	}

	@Column(length = 1000)
	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(referencedColumnName = "id")
	public ApplicationVersion getAppVersion() {
		return appVersion;
	}

	public void setAppVersion(ApplicationVersion appVersion) {
		this.appVersion = appVersion;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Timestamp getDate() {
		return date;
	}

	public void setDate(Timestamp date) {
		this.date = date;
	}

}
